package com.sky.controller.user;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.user.UserHistoryOrdersService;

import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@Slf4j
@Api(tags = "历史订单相关接口")
@RequestMapping("/user/order")
public class UserHistoryOrdersController {
    @Autowired
    private UserHistoryOrdersService userHistoryOrdersService;
    @GetMapping("/historyOrders")
    @ApiOperation("历史订单")
    public Result<PageResult> historyOrders(OrdersPageQueryDTO ordersPageQueryDTO) {
        log.info("历史订单:{}",ordersPageQueryDTO);
        PageResult result=userHistoryOrdersService.historyOrders(ordersPageQueryDTO);
        return Result.success(result);
    }
    @GetMapping("/orderDetail/{id}")
    @ApiOperation("订单详情")
    public Result<OrderVO> getById(@PathVariable Long id) {
        log.info("订单详情:{}",id);
        OrderVO orderVO=userHistoryOrdersService.getById(id);
        return Result.success(orderVO);
    }
    @PostMapping("/cancel/{id}")
    @ApiOperation("取消订单")
    public Result<String> cancel(@PathVariable Long id) {
        log.info("取消订单:{}",id);
        userHistoryOrdersService.cancel(id);
        return Result.success();
    }
    @PostMapping("/repetition/{id}")
    @ApiOperation("再来一单")
    public Result<String> repetition(@PathVariable Long id) {
        log.info("再来一单:{}",id);
        userHistoryOrdersService.repetition(id);
        return Result.success();
    }
}
